﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Document = NetBay.Core.BusinessEntities.Document;
using ImageRio = Rio.Framework.WCFService.RioWcfServices.ImageRio;
using Rio.Framework.Pages.Helpers.Utils;
using System.Collections;

namespace Rio.Framework.Pages.Events
{
    /// <summary>
    /// Delegate definition
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="DocumentSelectedEventArgs"/> instance containing the event data.</param>
    public delegate void DocumentSelectedHandler(object sender, DocumentSelectedEventArgs args);

    /// <summary>
    /// Event arguments used by DocumentSelectedHandler
    /// </summary>
    public class DocumentSelectedEventArgs : EventArgs
    {
        /// <summary>
        /// List of Selected document
        /// </summary>
        public List<Document> p_oListDocument { get; set; }

        /// <summary>
        /// List of all images
        /// </summary>
        private IList IListAllRioImages { get; set; }

        /// <summary>
        /// List of all images rio (import only)
        /// </summary>
        public ObservableCollection<ImageRio> ListAllRioImages
        {
            get
            {
                return IListAllRioImages as ObservableCollection<ImageRio>;
            }
            set
            {
                IListAllRioImages = value;
            }
        }
        
        /// <summary>
        /// Gets or sets the list all rio images search.
        /// </summary>
        /// <value>The list all rio images search.</value>
        public ObservableCollection<ImageRioSearch> ListAllRioImagesSearch
        {
            get
            {
                return IListAllRioImages as ObservableCollection<ImageRioSearch>;
            }
            set
            {
                IListAllRioImages = value;
            }
        }


        /// <summary>
        /// List of all filenames
        /// </summary>
        public List<string> ListAllFileName { get; set; }
        /// <summary>
        /// Index of the selected document
        /// </summary>
        public int SelectedDocumentIndex { get; set; }
        /// <summary>
        /// Gets or sets the selected image  (import only)
        /// </summary>
        public ImageRio SelectedImage { get; set; }
        /// <summary>
        /// Return the content of "ListAllFileName" as a list of ImageRio 
        /// </summary>
        public List<ImageRio> ListAllSelectedFiles
        {
            get
            {
                List<ImageRio> l_oReturnList = new List<ImageRio>();
                if (ListAllFileName != null && ListAllFileName.Count > 0)
                {
                    if (ListAllRioImages != null && ListAllRioImages.Count > 0)
                    {
                        foreach (string l_sFileName in ListAllFileName)
                        {
                            l_oReturnList.Add(ListAllRioImages.Where(i => Utils.RemoveExtension(i.Name).Equals(l_sFileName)).FirstOrDefault());
                        }
                    }
                }
                return l_oReturnList;
            }
        }

        public DocumentSelectedEventArgs()
            : this(null, null, -1)
        {
        }

        public DocumentSelectedEventArgs(List<Document> Documents, ObservableCollection<ImageRio> SelectedImages)
            :this(Documents,SelectedImages,-1)
        {
        }

        public DocumentSelectedEventArgs(List<Document> Documents, ObservableCollection<ImageRio> SelectedImages, int SelectedDocumentIndex)
        {
            this.p_oListDocument = Documents;
            this.ListAllRioImages = SelectedImages;
            this.SelectedDocumentIndex = SelectedDocumentIndex;
        }

        
    }
}
